import mongoose, { Document, Schema } from 'mongoose';

// 定义盲盒接口
export interface IPrize extends Document {
    name: string;
    description: string;
    image: string; // 盲盒图片 URL
    // price: number; // 价格
    balanceCost: number; // 价格
    stock: number; // 盲盒库存
    productInfo: any; // 商品信息，以 JSON 格式存储
    rule: 'probability' | 'fixed'; // 盲盒规则
    sellBeginTime: string; // 盲盒开始时间
    sellEndTime: string; // 盲盒结束时间
    longDesc: string;
    createdAt: string; // 创建时间
    updatedAt: string; // 更新时间
}

// 盲盒 Schema
const PrizeSchema: Schema = new Schema({
    name: { type: String, required: true },
    description: { type: String, required: true },
    image: { type: String },
    // price: { type: Number, required: true, default: 0 },
    balanceCost: { type: Number, required: true },
    stock: { type: Number, required: true },
    productInfo: { type: Schema.Types.Mixed, required: true }, // 使用 Mixed 类型存储任意 JSON 数据
    rule: {
        type: String,
        required: true
    },
    sellBeginTime: { type: String, required: true },
    sellEndTime: { type: String, required: true },
    longDesc: { type: String, },
    createdAt: { type: String },
    updatedAt: { type: String },
});

// 创建并导出 BlindBox 模型
const BlindBox = mongoose.model<IPrize>('BlindBox', PrizeSchema);

export default BlindBox;
